//
//  OutsideViewController.m
//  MySport
//
//  Created by lanou3g on 16/2/26.
//  Copyright © 2016年 ccsobj. All rights reserved.
//

#import "OutsideViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MySport-swift.h>
#import "FunctionView.h"


@interface OutsideViewController ()<CLLocationManagerDelegate,MKMapViewDelegate>

@property (nonatomic, strong)MKMapView *mapView;

@property (nonatomic,strong)CLLocationManager *CLManager;

@property (nonatomic,assign)BOOL functionOpen;

@property (nonatomic,strong)FunctionView *functionV;

@property (nonatomic,strong)UIButton *functionVButton;

@end

@implementation OutsideViewController

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.mapView = [[MKMapView alloc]initWithFrame:[UIScreen mainScreen].bounds];
        [self.view addSubview:self.mapView];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置功能界面开启
    self.functionOpen = YES;
    
    //打开功能页面按键
    [self addButton];
    
    //添加功能页面
    [self addFunctionView];
    
    //fuck
    self.CLManager.delegate = self;
    self.mapView.delegate = self;
    self.mapView.showsUserLocation = YES;
    [self.CLManager requestAlwaysAuthorization];
    [self.CLManager requestWhenInUseAuthorization];
    [self.CLManager startUpdatingLocation];
    self.mapView.userTrackingMode = MKUserTrackingModeFollow;
    // 开始定位
    [self.CLManager startUpdatingLocation];
    // Do any additional setup after loading the view.
}

-(void)addButton{
    
    self.functionVButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    self.functionVButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 40, [UIScreen mainScreen].bounds.size.height*0.4 - 40, 30, 30);
    
    _functionVButton.backgroundColor = [UIColor redColor];
    
    _functionVButton.alpha = 1;
    
    [_functionVButton addTarget:self action:@selector(functionSwitch:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.mapView addSubview:_functionVButton];
    
}

-(void)functionSwitch:(UIButton*)sender{
    
    if (self.functionOpen == YES)
    {
        
        self.functionV.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height*0.9, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height*0.1);

        self.functionOpen = NO;
    }
    else if (self.functionOpen == NO)
    {
        
       self.functionV.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height*0.4, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height*0.6);
        
        self.functionOpen = YES;
    }
    

    
    
}

-(void)addFunctionView{
    
    self.functionV = [[FunctionView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height*0.4, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height*0.6)];
    
    self.functionV.backgroundColor = [UIColor grayColor];
    
    [self.mapView addSubview:self.functionV];
    
}


-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    NSLog(@"更新userlocation");
}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
    
    NSLog(@"更新manager");
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
